package com.tuweiya.study.springmvc002.controller;

import com.tuweiya.study.springmvc002.eventBus.bus.SendEventBus;
import com.tuweiya.study.springmvc002.eventBus.bus.TimeEventBus;
import com.tuweiya.study.springmvc002.eventBus.event.CommonEvent;
import com.tuweiya.study.springmvc002.eventBus.event.EmailEvent;
import com.tuweiya.study.springmvc002.eventBus.event.ShortMsgEvent;
import com.tuweiya.study.springmvc002.eventBus.event.TimeExpiringEvent;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @Author: Mr_tu
 * @Date: Create in 16:18 2018/6/7
 * @Description:
 */
@Api(tags = "EventBusController", description = "处理EventBus")
@Controller
@RequestMapping(value = "/eventBus")
public class EventBusController {

    @GetMapping(value = "/sendShortMsg")
    @ResponseBody
    @ApiOperation(value = "调用短信事件")
    public String sendShortMsg() {

        System.out.println("send ShortMsg ...1...");
        System.out.println("send ShortMsg ...2...");
        System.out.println("send ShortMsg ...3...");
        System.out.println("send ShortMsg ...4...");
        SendEventBus.post(new ShortMsgEvent(10));
        System.out.println("send ShortMsg ...5...");
        System.out.println("send ShortMsg ...6...");
        System.out.println("send ShortMsg ...7...");
        System.out.println("send ShortMsg ...8...");

        return "sendShortMsg";
    }

    @GetMapping(value = "/sendEmail")
    @ResponseBody
    @ApiOperation(value = "调用邮件事件")
    public String sendEmail() {

        System.out.println("send Email ...1...");
        System.out.println("send Email ...2...");
        System.out.println("send Email ...3...");
        System.out.println("send Email ...4...");
        SendEventBus.post(new EmailEvent());
        System.out.println("send Email ...5...");
        System.out.println("send Email ...6...");
        System.out.println("send Email ...7...");
        System.out.println("send Email ...8...");

        return "sendEmail";
    }

    @GetMapping(value = "/handleTimeExpiring")
    @ResponseBody
    @ApiOperation(value = "调用时间过期事件")
    public String handleTimeExpiring() {
        System.out.println("handle time expiring ...1...");
        System.out.println("handle time expiring ...2...");
        System.out.println("handle time expiring ...3...");
        System.out.println("handle time expiring ...4...");
        TimeEventBus.post(new TimeExpiringEvent());
        System.out.println("handle time expiring ...5...");
        System.out.println("handle time expiring ...6...");
        System.out.println("handle time expiring ...7...");

        return "TimeExpiring";
    }


    @GetMapping(value = "/sendAll")
    @ResponseBody
    @ApiOperation(value = "调用同步异步事件")
    public String sendAll() {
        System.out.println("send all ....1....");
        System.out.println("send all ....2....");
        System.out.println("send all ....3....");
        SendEventBus.post(new ShortMsgEvent(5));
        System.out.println("send all ....4....");
        System.out.println("send all ....5....");
        System.out.println("send all ....6....");
        System.out.println("send all ....7....");
        SendEventBus.post(new EmailEvent());
        System.out.println("send all ....8....");
        System.out.println("send all ....9....");

        return "Send ALL";
    }

    @GetMapping(value = "/sendAll2")
    @ApiOperation(value = "调用公共事件")
    @ResponseBody
    public String sendCommonEvent(){
        System.out.println("CommonEvent .....1.....");
        System.out.println("CommonEvent .....2.....");
        SendEventBus.post(new CommonEvent());
        System.out.println("CommonEvent .....3.....");
        System.out.println("CommonEvent .....4.....");
        System.out.println("CommonEvent .....5.....");
        System.out.println("CommonEvent .....6.....");
        TimeEventBus.post(new CommonEvent());
        System.out.println("CommonEvent .....7.....");
        System.out.println("CommonEvent .....8.....");
        System.out.println("CommonEvent .....9.....");


        return "CommonEvent";
    }


}
